package edu.upf.da.samples.datagram.server;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ChatServidor {
	private DatagramSocket socketServidor = null;
	private DatagramPacket paqueteRecepcion;

	public ChatServidor() {
		super();
	}

	public static void main(java.lang.String[] args) {
		ChatServidor chat = new ChatServidor();
		chat.servidor();
	}

	public void servidor() {
		try {
			socketServidor = new DatagramSocket(6992);
			while (socketServidor != null) {
				paqueteRecepcion = new DatagramPacket(new byte[4000], 4000);
				socketServidor.receive(paqueteRecepcion);
				System.out.write(paqueteRecepcion.getData(), 0,
						paqueteRecepcion.getLength());
				System.out.print("\r\n");
			}
		} catch (SocketException se) {
			se.printStackTrace();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}
}
